var express = require('express');
var router = express.Router();
var pool = require('../db')

// 登录接口
router.post('/login', function (req, res, next) {
  // post传参  req.body
  // get传参   req.query
  const { userName, passWord } = req.body
  // 查询数据  pool.query(sql, callback)
  // 带条件查询
  // * 如果是字符串类型需要带 ''
  pool.query(`select * from user where name='${userName}' and password='${passWord}'`, (err, data) => {
    if (err) {
      res.send({
        code: 0,
        message: "sql语句错误"
      })
    } else {
      if (data.length > 0) {
        res.send({
          code: 1,
          message: "登录成功",
        })
      } else {
        res.send({
          code: 0,
          message: "请去注册"
        })
      }
    }
  })
})


module.exports = router;